<?php
/**
 * +--------------------------------------------------------------
 * | eLuoPHP
 * +--------------------------------------------------------------
 * | Copyright (c) 2013-2019 http://qxwoo.cn All rights reserved.
 * +--------------------------------------------------------------
 * | y139w <y139w@163.com>
 * +--------------------------------------------------------------
 * | 2019/06/21 23:29:06
 * +--------------------------------------------------------------
 * | Date.php
 * +--------------------------------------------------------------
 */


namespace luo\traits;


trait Date
{

    /**
     * @param $pattern
     * @param int $time
     * @return false|string
     */
    public static function format($pattern, $time = 0){
        $pattern = trim($pattern);
        if(!$time){
            $time = time();
        }
        return date($pattern, $time);
    }

    /**
     * @param int $time
     * @param string $format
     * @return false|string
     */
    public static function dateTime($time = 0, $format = 'Y-m-d H:i:s'){

        return self::format($format, $time);

    }

    /**
     * @param int $time
     * @return false|string
     */
    public static function date($time = 0){

        return self::format('Y-m-d', $time);

    }

    /**
     * @param int $time
     * @return false|string
     */
    public static function dateHourMinute($time = 0){

        return self::format('Y-m-d H:i', $time);

    }

    /**
     * @param int $time
     * @return false|string
     */
    public static function dateHour($time = 0){

        return self::format('Y-m-d H', $time);

    }

    /**
     * @param int $time
     * @return false|string
     */
    public static function yearMonth($time = 0){

        return self::format('Y-m', $time);

    }

    /**
     * @param int $time
     * @return false|string
     */
    public static function year($time = 0){

        return self::format('Y', $time);

    }

    /**
     * @param int $time
     * @return false|string
     */
    public static function month($time = 0){

        return self::format('m', $time);

    }

    /**
     * @param int $time
     * @return false|string
     */
    public static function day($time = 0){

        return self::format('d', $time);

    }

    /**
     * @param int $time
     * @return false|string
     */
    public static function hour($time = 0){

        return self::format('H', $time);

    }

    /**
     * @param int $time
     * @return false|string
     */
    public static function minute($time = 0){

        return self::format('i', $time);

    }

    /**
     * @param int $time
     * @return false|string
     */
    public static function second($time = 0){

        return self::format('s', $time);

    }

    /**
     * @param int $time
     * @return false|string
     */
    public static function week($time = 0){

        return self::format('w', $time);

    }

}